#pragma once

#define DIRECTINPUT_VERSION 0x0800

#include <dinput.h>
#include <Windows.h>
#pragma comment(lib, "dinput8.lib")
#pragma comment(lib, "dxguid.lib")

enum eMouseButtons
{
	LEFT_MOUSE_BUTTON,
	RIGHT_MOUSE_BUTTON,
	MIDDLE_MOUSE_BUTTON
};

class DInput
{
private:
	DInput();						// the ctor in the private allows this to only be used as a singleton
	POINT					m_CursorPos;
	HWND					m_hWnd;
	IDirectInput8*			m_pDIObject;
	LPDIRECTINPUTDEVICE8	m_pDIKeyboard;
	LPDIRECTINPUTDEVICE8	m_pDIMouse;
	char					m_kbBuffer[256];
	bool					m_kbWasHit[256];
	DIMOUSESTATE			m_mouseState;
	bool					m_bInitialized;		// whether DInput::Init() has been successfully called

public:
	inline static DInput* Engine()
	{ static DInput di; return &di; }

	bool m_bMouseButtonDown[4];

	bool	Init(HWND hWnd, HINSTANCE hInst);
	bool	PollDevices();
	bool	keyHeld(unsigned char key);		// returns true if the key is being held down
	bool	keyPressed(unsigned char key);	// returns true if a key has been pressed down
	bool	mouseButtonDown(int button);
	bool	mouseButtonHit(int button);
	float	mouseDX();
	float	mouseDY();
	float	mouseDZ();
	float	mouseXPos() { return (float)m_CursorPos.x; }
	float	mouseYPos() { return (float)m_CursorPos.y; }
	~DInput();
};